// 临时脚本：检查Essay数据
import dotenv from 'dotenv';
import { Sequelize, DataTypes } from 'sequelize';

dotenv.config();

const sequelize = new Sequelize(
  process.env.DB_NAME,
  process.env.DB_USER,
  process.env.DB_PASSWORD,
  {
    host: process.env.DB_HOST,
    dialect: 'mysql',
  }
);

(async () => {
  try {
    const [essays] = await sequelize.query(
      `SELECT 
        id, 
        title, 
        LEFT(content, 300) as content_preview,
        status,
        score,
        LEFT(JSON_EXTRACT(correctionResult, '$.corrections'), 500) as corrections_preview
      FROM Essays 
      ORDER BY createdAt DESC 
      LIMIT 1`,
      { type: 'SELECT' }
    );

    console.log('=== 最新Essay数据 ===');
    console.log(JSON.stringify(essays, null, 2));

    await sequelize.close();
    process.exit(0);
  } catch (error) {
    console.error('Error:', error);
    await sequelize.close();
    process.exit(1);
  }
})();

